package red.mlz.consoleconsumer.controller.upload;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import red.mlz.common.utils.Response;
import red.mlz.consoleconsumer.feign.upload.UploadFeign;

@RestController
@Slf4j
public class UploadController {

    @Autowired
    private UploadFeign uploadFeign;

    @PostMapping("/upload")
    public Response uploadFile(@RequestPart("file") MultipartFile file) {
        return new Response(1001,uploadFeign.uploadFile(file));
    }

    @PostMapping("/oss/upload")
    public Response upload(
            @RequestPart("file") MultipartFile file,
            @RequestParam(value = "width", required = false) Integer width,
            @RequestParam(value = "height", required = false) Integer height
    ){
        return new Response(1001,uploadFeign.upload(file, width, height));
    }
}
